package com.tianhui.consignortwofei.mvp.ui.activity.hetong.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fgs.common.other.CommonEvent;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.hetong.DuiXIangListBean;
import com.tianhui.consignortwofei.myview.MyLinearLayoutManager;
import com.tianhui.consignortwofei.other.EventWhat;


import org.greenrobot.eventbus.EventBus;
import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;
import org.yczbj.ycrefreshviewlib.inter.OnItemClickListener;

/**
 * @author fgs
 * @date 2020/4/1
 * @description
 **/
public class DuiXiangOneListAdapter extends RecyclerArrayAdapter<DuiXIangListBean> {


    private Context mContext ;
//    private OrderOperateView.OnOrderOperateClickListener onOrderOperateListener;

    public DuiXiangOneListAdapter(Context context) {//, IOrderStatus iOrderStatus
        super(context);
        mContext=context;
//        this.iOrderStatus = iOrderStatus;
    }

//    public void setOnOrderOperateListener(OrderOperateView.OnOrderOperateClickListener onOrderOperateListener) {
//        this.onOrderOperateListener = onOrderOperateListener;
//    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        ShopFenLeiViewHolder viewHolder = new ShopFenLeiViewHolder(parent, R.layout.item_duixiang_one);
        return viewHolder;
//        switch (viewType) {
//            case 0:
//                return new newsSmallImgViewHolder(parent, R.layout.item_news_small);
//            case 1:
//                return new newsThreeViewHolder(parent, R.layout.item_news_three_image);
//
//            case 2:
//                return new newsBigImgViewHolder(parent, R.layout.item_video_big);
//            case 3:
//                return new newsMomentsViewHolder(parent, R.layout.item_moments_text);
//        }
//        return null;


    }





    public class ShopFenLeiViewHolder extends BaseViewHolder<DuiXIangListBean> {
//        private TextView numberTextView;
//        private ImageView bigTvImage;
        private TextView bigTvTitle;
        private RecyclerView rv_option_body;



        public ShopFenLeiViewHolder(ViewGroup parent, int res) {
            super(parent, res);
//            numberTextView = getView(R.id.item_order_list_numberTextView);
//            bigTvImage = (ImageView) getView(R.id.big_tv_image);
            bigTvTitle = (TextView) getView(R.id.tv_title);
            rv_option_body = (RecyclerView) getView(R.id.rv_option_body);



//            addOnClickListener(R.id.rv_option_body);
//            bigTvTime = (TextView) getView(R.id.big_tv_time);
//            bigTvCommentNum = (TextView) getView(R.id.big_tv_comment_num);
//            bigIvComment = (ImageView) getView(R.id.big_iv_comment);
//            bigTvLikeNum = (TextView) getView(R.id.big_tv_like_num);
//            bigIvLike = (ImageView) getView(R.id.big_iv_like);

        }

        @Override
        public void setData(DuiXIangListBean data) {
            super.setData(data);

//            if (null!=data.getImages()&&0<data.getImages().size()) {
//                String image = Config.baseImageUrlTwo+ data.getImg();
//                LoadImageUtils.loadFilletImage(mContext, image, bigTvImage,10);
//            }


            bigTvTitle.setText(data.getName());


//            List<ShopFenLeiListBean.CategoryListDTO.ChildrenDTO> details = data.getChildren();

            if (data.isShowChild()){
                rv_option_body.setVisibility(View.VISIBLE);
            }else {
                rv_option_body.setVisibility(View.GONE);
            }

            rv_option_body.setFocusable(false);
            if (null != data.getChildren() && data.getChildren().size() > 0) {

//            MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(getContext());
                MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(getContext(),
                        LinearLayoutManager.VERTICAL, false) {
                    @Override
                    public boolean canScrollVertically() {
                        return false;
                    }
                };
//            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                rv_option_body.setLayoutManager(linearLayoutManager);
                DuiXiangListTwoAdapter homeListAdapter = new DuiXiangListTwoAdapter(getContext());
                rv_option_body.setAdapter(homeListAdapter);
//            homeListAdapter.clear();
                homeListAdapter.addAll(data.getChildren());
                homeListAdapter.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(int position) {

                        DuiXIangListBean.ChildrenDTO data = homeListAdapter.getAllData().get(position);
                        EventBus.getDefault().post(new CommonEvent(EventWhat.EVENT_REFRESH_DUIXIANG_LIST.getValue(),data.getName(),data.getId()+""));
//                        if (data == null) {
//                            return;
//                        }
//                        Intent  intent=new Intent(mContext, HuatiDetailActivity.class);
//                        intent.putExtra("beanId",data.getId());
//                        mContext.startActivity(intent);
                    }
                });
            }

        }
    }










}
